#include "mqtt.h"
#include "json.h"

using namespace std;

struct mosquitto *mosq;
const char *version = "v1.0.1";

int main()
{
    int qos = 0;
    string topic   = "test";
    string message = rapidjson_generate_json();
    printf("version: %s\n", version);

    mosquitto_mqtt_init(&mosq);
    mosquitto_mqtt_connect_callback_set(mosq);
    mosquitto_mqtt_message_callback_set(mosq);
    mosquitto_mqtt_disconnect_callback_set(mosq);
    mosquitto_mqtt_connect(mosq);
    mosquitto_loop_start(mosq);

    while(1)
    {
        if(is_connect == CONNECT_SUCCESS)
        {
            mosquitto_mqtt_publish(mosq, topic, message, qos);
        }
        sleep(15);
    }

    mosquitto_loop_stop(mosq, true); //mosquitto_loop_start
    mosquitto_disconnect(mosq);      //mosquitto_connect
    mosquitto_destroy(mosq);         //mosquitto_new
    mosquitto_lib_cleanup();         //mosquitto_lib_init
    return 0;
}